package org.csu.agrisupply.api.controller.front;

import org.csu.agrisupply.api.common.CommonResponse;
import org.csu.agrisupply.api.entity.Form;
import org.csu.agrisupply.api.entity.Item;
import org.csu.agrisupply.api.entity.User;
import org.csu.agrisupply.api.service.FormService;
import org.csu.agrisupply.api.service.ItemService;
import org.csu.agrisupply.api.vo.FormVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/forms/")
public class FormController {
    @Autowired
    private FormService formService;

    @GetMapping("")
    @ResponseBody
    //得到所有采购单
    public CommonResponse<List<FormVo>> getFormList(){
        return formService.getFormList();
    };
    @GetMapping("{formId}")
    @ResponseBody
    //得到单个采购单
    public CommonResponse<FormVo> getForm(@PathVariable("formId") String formId){
        return formService.getForm(formId);
    };
    @PostMapping("users/{userId}")
    @ResponseBody
    //发布采购单
    public CommonResponse<Form> createForm(@PathVariable("userId") String userId,
                                           @RequestBody Form form){
        return formService.createForm(userId,form);
    }
    @GetMapping("users/{userId}")
    @ResponseBody
    //根据userId得到采购单
    public CommonResponse<List<FormVo>> getFormbyUserId(@PathVariable("userId") String userId){
        return formService.getFormbyUserId(userId);
    };

    @GetMapping("users/{userId}/filter")
    @ResponseBody
    //得到除了已经完成的订单和自己已经供货的订单
    public CommonResponse<List<FormVo>> getFormFilter(@PathVariable("userId") String userId){
        return formService.getFormFilter(userId);
    };


}
